//
//  HProductHeaderView.swift
//  StarTimesON
//
//  Created by Toj on 7/18/23.
//  Copyright © 2023 StarTimes. All rights reserved.
//

import UIKit

class HProductHeaderView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupMakeAddSubviews()
        setupMakeInitialize()
        setupMakeLayoutSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    
    /* <#NOTE#> */
    private lazy var backgroundImageView: UIImageView = {
        let view = UIImageView()
        view.image = "player_product_Header_bgimg".to_image
        return view
    }()
    
    /* <#NOTE#> */               
    private(set) lazy var accountInfoView: HPAccountInfoView = {
        let view = HPAccountInfoView()
        view.backgroundColor = .clear
        return view
    }()
    
    /* 商品平台: Mobile(OTT)/ TV(DVB) */
    private(set) lazy var platformView: HPPlatformView = {
        let view = HPPlatformView()
        return view
    }()
}

// MARK: - 点击事件/ 通知事件回调
@objc private extension HProductHeaderView {
    
}

// MARK: - Public
extension HProductHeaderView {
    
    func show(admobModel: STAdmobModel? = nil) {
        
        let isVIP = arc4random_uniform(2) == 1
        print("-->toj: isVIP: \(isVIP)")
        accountInfoView.setupCommodityInfo(isVIP: isVIP)
        
        var platformWidth = platformView.frame.width
        if isHidden {
            let isTV = arc4random_uniform(2) == 1
            print("-->toj: isTV: \(isTV)")
            platformView.setupPlatform(isTV: isTV)
            platformWidth = platformView.platformWidth(isTV: isTV)
        }
        let rightMargin = admobModel == nil ? 50 : 17
        platformView.snp.remakeConstraints { make in
            make.width.equalTo(platformWidth)
            make.right.equalTo(snp.right).offset(-rightMargin)
            make.top.bottom.equalTo(self)
        }
        isHidden = false
    }
    
    func hidden() {
        isHidden = true
    }
}

// MARK: - Private
private extension HProductHeaderView {
    
}

// MARK: - 初始化设置
private extension HProductHeaderView {
    
    func setupMakeAddSubviews() {
        addSubview(backgroundImageView)
        addSubview(platformView)
        addSubview(accountInfoView)
    }
    
    func setupMakeLayoutSubviews() {
        backgroundImageView.snp.makeConstraints { make in
            make.edges.equalTo(self)
        }
        
        platformView.snp.remakeConstraints { make in
            make.width.equalTo(160)
            make.right.equalTo(snp.right).offset(-50)
            make.top.bottom.equalTo(self)
        }
        
        accountInfoView.snp.makeConstraints { make in
            make.left.top.bottom.equalTo(self)
            make.right.equalTo(platformView.snp.left)
        }
    }
    
    func setupMakeInitialize() {
       
    }
}
